import sysConfig from "@/config"
import tool from '@/utils/tool'
import { createI18n } from 'vue-i18n'
import el_zh_cn from 'element-plus/lib/locale/lang/zh-cn'
import el_en from 'element-plus/lib/locale/lang/en'
import el_ja from 'element-plus/lib/locale/lang/ja'
import el_zh_tn from 'element-plus/lib/locale/lang/zh-tw'

import zh_cn from './lang/zh-cn.js'
import en from './lang/en.js'
import zh_tn from './lang/zh-tn.js'
import ja from './lang/ja.js'

const messages = {
	'zh_CN': {
		el: el_zh_cn,
		...zh_cn
	},
	'en_US': {
		el: el_en,
		...en
	},
	'zh_TW': {
		el: el_zh_tn,
		...zh_tn
	},
	'ja_JP': {
		el: el_ja,
		...ja
	}
}

const i18n = createI18n({
	locale: tool.data.get("APP_LANG") || sysConfig.LANG,
	fallbackLocale: 'zh_CN',
	globalInjection: true,
	messages,
})

// i18n.global.getTranslation = (key, lang) => tool.getTranslation(i18n, key, lang);

export default i18n;
